home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <cdr.h>
- #include <snd.h>
- #include "defs.h"
-
- extern BOOL Input();
- extern void wrtstr();
- extern int Sel_menu();
- extern char *SPCSTR;
-
- typedef struct {
- char min;
- char sec;
- char frame;
- } CDTIME;
-
- static short cd_act=FALSE;
- static int type=0,strt=0,endt=0;
- static int vol=64,sts=0,no=0,acv=0;
- static CDTIME st,ed;
- static CDTIME *track=NULL;
-
- int CD_open(void)
- {
- int i;
- CDTIME disc;
-
- if ( track == NULL &&
- (track = (CDTIME *)malloc(sizeof(CDTIME)*99)) == NULL )
- return 1;
-
- do {
- i = cdr_cdinfo(0,&type,&strt,&endt,(char *)track,(char *)&disc);
- } while ( i == CDERR7 );
-
- /*********************************
- char tmp[80];
- sprintf(tmp,"%d:%d:%d",disc.min,disc.sec,disc.frame);
- wrtstr(tmp,30,1,0x15);
- *********************************/
-
- if ( disc.frame-- <= 0 ) {
- disc.frame = 74;
- if ( disc.sec-- <= 0 ) {
- disc.sec = 59;
- if ( disc.min-- <= 0 )
- return 1;
- }
- }
- if ( i == 0 ) {
- track[endt].min = disc.min;
- track[endt].sec = disc.sec;
- track[endt].frame = disc.frame;
- acv = 1;
- }
-
- return i;
- }
- void CD_play()
- {
- int i;
- char tmp[80],ttl[40];
-
- if ( cdr_mphase(0,&sts,&no,(char *)&st,(char *)&ed) != 0 ) {
- wrtstr("CDが正常にセットされていません?",30,1,0x12);
- return;
- }
- if ( sts != 0 )
- cdr_pause(0);
-
- if ( CD_open() != 0 ) {
- wrtstr("CD情報の読み取りに失敗しました",30,1,0x12);
- return;
- }
-
- tmp[0] = '\0'; sprintf(ttl,"曲番(1-%d) ",endt);
- if ( Input(tmp,ttl) != FALSE )
- return;
- if ( (no = atoi(tmp) - 1) < 0 || no >= endt ) no = 0;
-
- SND_elevol_set(1,vol,vol);
- if ( endt > 0 ) {
- for ( i=no ; i < endt && (track[i].min & 0x80) != 0 ; i++ );
- if ( cdr_mtplay(0,(char *)&(track[i]),(char *)&(track[endt])) != 0 )
- wrtstr("正常に演奏出来ません",30,1,0x12);
- }
- if ( track != NULL )
- free(track);
- track = NULL;
- cd_act = TRUE;
- }
- void CD_stop()
- {
- cdr_mstop(0);
- if ( track != NULL )
- free(track);
- track = NULL;
- cd_act = FALSE;
- }
- void CD_endof()
- {
- if ( cd_act != FALSE )
- cdr_mstop(0);
- }
- void CD_vol()
- {
- char tmp[80];
-
- sprintf(tmp,"%d",vol);
- if ( Input(tmp,"音量(0-127) ") != FALSE )
- return;
- vol = atoi(tmp);
- SND_elevol_set(1,vol,vol);
- }
- void CD_menu()
- {
- static int no=ERR;
- static char *menu[]={
- "1 CD演奏する ",
- "2 CD演奏を止める ",
- "",
- "3 音量を設定する ",
- NULL };
-
- wrtstr(SPCSTR,30,1,0x1F);
- if ( Sel_menu(menu,30,2,&no) != FALSE )
- return;
-
- if ( no == 0 )
- CD_play();
- else if ( no == 1 )
- CD_stop();
- else if ( no == 2 )
- CD_vol();
- }